﻿// NahidaProject-Serialization-BuildExample.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <cassert>
#include <iostream>

#include <CSV.h>
#include <INIReader.h>
#include <INIWriter.h>
#include <JSON.h>
#include <XMLReader.h>
#include <XMLWriter.h>
#include <YAML.h>


int main(int argc, char** argv) {
	std::ofstream ofs("TestRead.csv", std::ios::out | std::ios::app);
	ofs << R"(a,b,c
1,2,3
4,5,6
7,8,9)" << std::endl;
	ofs.close();

	std::ifstream file("TestRead.csv");
	NahidaProject::CSV::CSV csv(file);

	for (auto& row : csv) {
		for (auto& field : row) {
			std::cout << field << " | ";
		}
		std::cout << "" << std::endl;
	}

	::remove("TestRead.csv");

	NahidaProject::INIWriter writer;
	writer.SetFileValue("Section1", "Key1", "Value1");
	writer.SetFileValue("Section1", "Key2", "Value2");
	writer.SetFileValue("Section1", "Key3", "Value3");
	writer.SetFileValue("Section2", "Key1", "Value1");
	writer.SetFileValue("Section2", "Key2", "Value2");
	writer.SetFileValue("Section2", "Key3", "Value3");

	writer.WriteINIFile("TestRead.ini");

	NahidaProject::INIReader reader;
	reader.ReadFile("TestRead.ini");

	assert(reader.GetValue("Section1", "Key1") == "Value1");
	assert(reader.GetValue("Section1", "Key2") == "Value2");
	assert(reader.GetValue("Section1", "Key3") == "Value3");
	assert(reader.GetValue("Section2", "Key1") == "Value1");
	assert(reader.GetValue("Section2", "Key2") == "Value2");
	assert(reader.GetValue("Section2", "Key3") == "Value3");

	::remove("TestRead.ini");

	NahidaProject::JSON json;
	json.Parse(R"({"name": "Jack", "age": 18, "area": ["c++", "php", "python", "go"], "hobby": {"hobby1": "reading", "hobby2": "coding", "hobby3": "basketball"}})");
	assert(json["name"].ToString() == "\"Jack\"");
	assert(json["age"].ToString() == "18");
	assert(json["area"].ToString() == R"(["c++","php","python","go"])");
	assert(json["hobby"]["hobby1"].ToString() == "\"reading\"");
	assert(json["hobby"]["hobby2"].ToString() == "\"coding\"");
	assert(json["hobby"]["hobby3"].ToString() == "\"basketball\"");

	json.Clear();

	NahidaProject::XMLWriter xmlWriter;
	NahidaProject::XMLWriterNode& documentNode = xmlWriter["DocumentNode"];
	documentNode["Key0"]("Index", "0")("Size", "test");
	documentNode["Key1"]("Index", "1")("Size", "test");
	documentNode["Key2"]("Index", "2")("Size", "test");

	documentNode["Key0"]["AnotherKey"] = "Value0";
	documentNode["Key1"]["AnotherKey"] = "Value1";
	documentNode["Key2"]["AnotherKey"] = "Value2";

	documentNode["Key0"]["AnotherKey"]["Another"]("Attribute0", "Value0") = "Test0";
	documentNode["Key1"]["AnotherKey"]["Another"]("Attribute0", "Value0") = "Test1";

	xmlWriter.OutputFile("TestRead.xml");

	/*
	XMLReader::XMLNode xmlNode;
	std::cout << xmlNode.FromFile("TestRead.xml");
	xmlNode.Print();
	XMLReader::XMLNode* node2 = xmlNode.GetChildPtrByName("xml");
	XMLReader::XMLNode* node3 = node2->GetChildPtrByName("DocumentNode");
	XMLReader::XMLNode* node4 = node3->GetChildPtrByName("Key0");
	std::cout << node4->GetAttribute("Index") << std::endl;
	*/
	::remove("TestRead.xml");

	std::ofstream ofs1("TestRead.yml", std::ios::out | std::ios::app);
	ofs1 << R"(text: How are you? I am fine Thank you
number: 78.91
boolValue: true
outer_object:
  inner_object:
    name: Ningguang
  name: Ganyu)" << std::endl;
	ofs1.close();

	NahidaProject::YAML::YAML yaml("TestRead.yml");
	assert(yaml["text"].cast<std::string>() == "How are you? I am fine Thank you");
	assert(yaml["number"].cast<double>() == 78.91);
	assert(yaml["boolValue"].cast<bool>());
	assert(yaml["outer_object"]["inner_object"]["name"].cast<std::string>() == "Ningguang");
	assert(yaml["outer_object"]["name"].cast<std::string>() == "Ganyu");

	::remove("TestRead.yml");

	return 0;
}

// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
// 调试程序: F5 或调试 >“开始调试”菜单

// 入门使用技巧: 
//   1. 使用解决方案资源管理器窗口添加/管理文件
//   2. 使用团队资源管理器窗口连接到源代码管理
//   3. 使用输出窗口查看生成输出和其他消息
//   4. 使用错误列表窗口查看错误
//   5. 转到“项目”>“添加新项”以创建新的代码文件，或转到“项目”>“添加现有项”以将现有代码文件添加到项目
//   6. 将来，若要再次打开此项目，请转到“文件”>“打开”>“项目”并选择 .sln 文件
